package cn.liuhuan1.blogsModel.service;

import cn.liuhuan1.blogsModel.dao.AfterUserDao;
import cn.liuhuan1.webModelBean.api.AfterUserImp;
import cn.liuhuan1.webModelBean.bo.AfterUserBo;
import cn.liuhuan1.webModelBean.vo.AfterUserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: liuhuan
 * @Date: 2021/2/19 - 02 - 19 - 14:54
 * @Description:
 * @version: 1.0
 */
@Service
public class AfterUserService implements AfterUserImp {

    @Autowired
    private AfterUserDao afterUserDao;

    @Override
    public AfterUserVo afterLogin(String userName, String password) {
        if (userName.trim().length() > 0 && password.trim().length() > 0) {
            List<AfterUserVo> afterUserVoList = afterUserDao.afterLogin(userName, password);
            if(afterUserVoList == null){
                return null;
            }
            return afterUserVoList.get(0);
        } else {
            return null;
        }
    }

    @Override
    public AfterUserVo afterInfo(String token) {
        AfterUserVo afterUserVo = afterUserDao.afterInfo(token);
        return afterUserVo;
    }

    @Override
    public void updateLogin(AfterUserBo afterUserBo) {
        if(afterUserBo.getId() == null || afterUserBo.getId().trim() == ""){
            throw new NullPointerException();
        }
        afterUserDao.updateLogin(afterUserBo);
    }
}
